package com.itheima.service.db.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.SmsFlashPromotion;
import com.itheima.mapper.SmsFlashPromotionMapper;
import com.itheima.service.db.SmsFlashPromotionService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SmsFlashPromotionServiceImpl implements SmsFlashPromotionService {

    @Autowired
    SmsFlashPromotionMapper smsFlashPromotionMapper;

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize, String keyword) {
        Page<SmsFlashPromotion> page = new Page<>(pageNum, pageSize);

        LambdaQueryWrapper<SmsFlashPromotion> qw = new LambdaQueryWrapper<>();

        qw.like(StrUtil.isNotEmpty(keyword), SmsFlashPromotion::getTitle, keyword);

        Page<SmsFlashPromotion> smsFlashPromotionPage = smsFlashPromotionMapper.selectPage(page, qw);

        return new PageBeanVo(pageNum, pageSize, smsFlashPromotionPage.getTotal(), smsFlashPromotionPage.getRecords());
    }

    @Override
    public SmsFlashPromotion findById(Long id) {
        return smsFlashPromotionMapper.selectById(id);
    }

    @Override
    public void update(SmsFlashPromotion smsFlashPromotion) {
        smsFlashPromotionMapper.updateById(smsFlashPromotion);
    }

    @Override
    public void deleteById(Long id) {
        smsFlashPromotionMapper.deleteById(id);
    }

    @Override
    public Integer create(SmsFlashPromotion smsFlashPromotion) {
        return smsFlashPromotionMapper.insert(smsFlashPromotion);

    }
}
